<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 楼栋信息
 */
class Ldxx extends Common
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRiaght = '*';
    protected $ldxxModel = null;
    protected $ldxxCategoryModel = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->ldxxModel = new \app\admin\model\Ldxx();
        $this->ldxxCategoryModel =new \app\admin\model\LdxxCategory();
    }
    /**
     * 楼栋信息分类列表
     *
     */
    public function getldxxCategoryList()
    {
        $ldxxCategory = $this->ldxxCategoryModel
            ->select();
        $this->outputData($ldxxCategory);
    }
    /**
     * 楼栋信息列表
     */
    public function getldxxList()
    {
        $page = $this->request->get('page') - 1;
        $page=$page>0?$page:0;
        $limit = $this->request->get('pageSize');
        $limit=$limit>0?$limit:5;
        $start = $page * $limit;
        $catid=$this->request->get('catid');
		$zhuangtai = $this->request->get('zhuangtai');
		$dengji=$this->request->get('dengji');
		$where=[];
        //按分类
        if($catid){
            $where['catid']=$catid;
        }
		//按等级
        if(isset($dengji)){
            $where['f.dengji']=$dengji;
        }
        $ldxxList = $this->ldxxModel
            ->alias('f')
            ->join('LdxxCategory fc','f.catid=fc.id')
            ->where($where)
            ->field('f.*,fc.name')
            ->limit($start,$limit)
            ->select();
		foreach ($ldxxList as &$value){
            $value['level']=str_replace([0,1,2],['宽管级','关注级','严管级'],$value['dengji']);
        }
        $this->outputData($ldxxList);
    }
    /**
     * 楼栋信息
     */
    public function getldxxDetail()
    {
        $id=$this->request->get('id');
        $fwbm=$this->request->get('fwbm');
        $where=[];
        if(is_numeric($id)){
            $where['f.id']=$id;
        }else {
            if ($fwbm) {
                $where['f.ldbh'] = $fwbm;
            }
        }
        $ldxxList = $this->ldxxModel
            ->alias('f')
            ->join('LdxxCategory fc','f.catid=fc.id')
            ->where($where)
            ->find();
        if($ldxxList) {
            $ldxxList['level'] = str_replace([0, 1, 2], ['宽管级', '关注级', '严管级'], $ldxxList['dengji']);
        }
		$this->outputData($ldxxList);
    }
}
